/**
 * Created by Administrator on 2018/8/24.
 */
let formatterZtree = function (list) {
  // 处理数据
  let firstMenu = []
  for (let i = 0; i < list.length; i++) {
    if (list[i].pId === '0') {
      let obj = list[i]
      obj.children = []
      firstMenu.push(obj)
      list.splice(i, 1)
      i--
    }
  }
  // 处理数据
  let menuList = function (arr) {
    if (list.length) {
      for (let k = 0; k < arr.length; k++) {
        for (let m = 0; m < list.length; m++) {
          if (list[m].pId === arr[k].id) {
            let obj = list[m]
            obj.children = []
            arr[k].children.push(obj)
            list.splice(m, 1)
            m--
          }
        }
        menuList(arr[k].children)
      }
    }
    return arr
  }
  return menuList(firstMenu)
}

export default {
  formatter: function (list) {
    return formatterZtree(list)
  }
}
